package dto

import (
	"danmu/model"
	"time"
)

type VideoDto struct {
	Vid       uint      `json:"vid"`
	Title     string    `json:"title"`
	Img       string    `json:"img"`
	Video     string    `json:"video"`
	VideoType string    `json:"type"`
	Content   string    `json:"content"`
	Uid       uint      `json:"uid"`
	Date      time.Time `json:"date"`
	IsShow    bool      `json:"show"`
}

type OneVideoDto struct {
	Vid        uint      `json:"vid"`
	Title      string    `json:"title"`
	Img        string    `json:"img"`
	Video      string    `json:"video"`
	VideoType  string    `json:"type"`
	Content    string    `json:"content"`
	Uid        uint      `json:"uid"`
	Date       time.Time `json:"date"`
	Favorites  int       `json:"favorites"`
	LikeCount  int       `json:"like_count"`
	AuthorInfo Author    `json:"author"`
}

type Author struct {
	Uid  uint   `json:"uid"`
	Name string `json:"name"`
	Face string `json:"face"`
	Sign string `json:"sign"`
}

func ToVideoDto(video []model.Video) []VideoDto {
	newVideo := make([]VideoDto, len(video))
	for i := 0; i < len(video); i++ {
		newVideo[i].Vid = video[i].ID
		newVideo[i].Title = video[i].Title
		newVideo[i].Content = video[i].Content
		newVideo[i].Img = video[i].CoverName
		newVideo[i].Video = video[i].VideoName
		newVideo[i].VideoType = video[i].VideoType
		newVideo[i].Uid = video[i].Uid
		newVideo[i].Date = video[i].CreatedAt
		newVideo[i].IsShow = video[i].IsShow
	}
	return newVideo
}

func ToOneVideoDto(video model.Video) OneVideoDto {
	var newVideo = OneVideoDto{}
	newVideo.Vid = video.ID
	newVideo.Title = video.Title
	newVideo.Img = video.CoverName
	newVideo.Video = video.VideoName
	newVideo.VideoType = video.VideoType
	newVideo.Content = video.Content
	newVideo.Favorites = video.Favorites
	newVideo.LikeCount = video.LikeCount
	newVideo.Uid = video.Uid
	newVideo.Date = video.CreatedAt
	newVideo.AuthorInfo.Uid = video.Uid
	newVideo.AuthorInfo.Name = video.Author.Name
	newVideo.AuthorInfo.Face = video.Author.Face
	newVideo.AuthorInfo.Sign = video.Author.Sign
	return newVideo
}

func ToVideoInfoDto(video []model.Video) []VideoDto {
	newVideo := make([]VideoDto, len(video))
	for i := 0; i < len(video); i++ {
		newVideo[i].Vid = video[i].ID
		newVideo[i].Title = video[i].Title
		newVideo[i].Content = video[i].Content
		newVideo[i].Uid = video[i].Uid
		newVideo[i].Img = video[i].CoverName
		newVideo[i].Date = video[i].CreatedAt
		newVideo[i].IsShow = video[i].IsShow
	}
	return newVideo
}
